import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 666
 * Date: 2023-03-25
 * Time: 15:47
 */
public class test3 {
    public static void main(String[] args) {
        Scanner q=new Scanner(System.in);
                int len= q.nextInt();
        int m=0;
        int max=q.nextInt();
        while (q.hasNext()){
            int a=q.nextInt();
            m=Math.max(m+a,a);
            max=Math.max(max,m);
        }
        System.out.println(max);
    }
}
